﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataparseEngine;

public partial class copyright : System.Web.UI.Page
{
    private String questURL = "http://www.sipo.gov.cn/sipo2008/zcfg/zcjd/";//"http://www.cnlaw.org.cn/soft/kstd/1.html";
    private String newsURL = "http://www.sipo.gov.cn/sipo2008/mtjj/bq2009/";
    private String policyURL = "http://www.sipo.gov.cn/sipo2008/zcfg/zcjd/";
    private String softURL = "http://www.cnlaw.org.cn/soft/kstd/";
    private DataparseEngine.DataProvider localProvider = new DataparseEngine.LocalDataProvider();
    private DataparseEngine.DataProvider remoteProvider = new DataparseEngine.RemoteDataProvider();

    protected void Page_Load(object sender, EventArgs e)
    {
        String str = remoteProvider.provide(questURL, "<ul(.|\n)*?</ul>").Replace("<ul>", "<ul style=\"border: 0px solid gray; width: 150px;margin-left:-15px;font-size:12px\">");
        DataparseEngine.UIUtil.createBulletList(this.policyBulletList, str,15);

        str = remoteProvider.provide(newsURL, "<ul(.|\n)*?</ul>").Replace("<ul>", "<ul style=\"border: 0px solid gray; width: 150px;margin-left:-15px;font-size:12px\">");
        DataparseEngine.UIUtil.createBulletList(this.newsBulletList, str, 15);

        createQuestionItems();
    }

    protected void createQuestionItems()
    {
        List<String> titles = ((LocalDataProvider)localProvider).createBulletTitles(Server.MapPath("~") + "/template/copyright.html");
        if (titles.Count != 0)
        {
            if (this.CopyrightQuestionBullet.Items.Count == 0)
            {
                for (int i = 0; i < titles.Count; i++)
                {
                    ListItem item = new ListItem(titles[i]);
                    CopyrightQuestionBullet.Items.Add(item);
                }
            }
        }
    }

    protected void NewBulletedListClick(object sender, BulletedListEventArgs e)
    {
        viewBulletDetail(newsURL, ((BulletedList)sender).Items[e.Index], "<div.*(?=q_wz)(.|\n)*?</div>");
    }

    protected void PolicyBulletedListClick(object sender, BulletedListEventArgs e)
    {
        viewBulletDetail(policyURL, ((BulletedList)sender).Items[e.Index], "<div.*(?=q_wz)(.|\n)*?</div>");
    }

    protected void QuestionItemClick(object sender, BulletedListEventArgs e)
    {

        viewBulletDetail(Server.MapPath("~") + "/template/copyright.html", "<div.*(?=" + e.Index + ")(.|\n)*?</div>");
    }

    private void viewBulletDetail(String url, String exp)
    {
        this.innerContent.InnerHtml = localProvider.provide(url, exp);
        back.Visible = true;
    }

    private void viewBulletDetail(String url, ListItem item, String exp)
    {
        this.innerContent.InnerHtml = "<h3 style=\"text-align:center\">" + item.Attributes["title"] + "</h3>" +
                                           remoteProvider.provide(url + item.Value, exp).Replace("盛邦", "天玺泽").Replace("align=\"center\"",
                                                                                                "align=\"left\"") +
                                           "</div>";
        back.Visible = true;
    }

    protected void ViewSoftDetails(object sender, BulletedListEventArgs e)
    {
        String value = ((BulletedList)sender).Items[e.Index].Value;
        String[] seperator = new string[] { ";" };
        String[] result = value.Split(seperator, System.StringSplitOptions.None);
        Boolean isRef = Boolean.Parse(result[0]);
        if (isRef)
        {
            viewBulletDetail(softURL, ((BulletedList)sender).Items[e.Index], "<div.*(?=tart)(.|\n)*?</div>");
        }
        else
        {
            Response.Redirect(result[1]);
        }
        back.Visible = true;
    }
}
